<template>
  <div class="users-page">
    <div class="page-header">
      <h2 class="page-title">用户管理</h2>
      <div class="header-actions">
        <div class="search-box">
          <svg viewBox="0 0 24 24" class="search-icon">
            <path d="M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z"/>
          </svg>
          <input type="text" placeholder="搜索用户名/手机号..." 
                 class="search-input" 
                 v-model="queryParams.keyword" 
                 @keyup.enter="handleSearch">
        </div>
        <select class="filter-select" v-model="queryParams.realNameStatus" @change="handleSearch">
          <option value="">全部认证状态</option>
          <option :value="REAL_NAME_STATUS.VERIFIED">已认证</option>
          <option :value="REAL_NAME_STATUS.UNVERIFIED">未认证</option>
        </select>
        <select class="filter-select" v-model="queryParams.status" @change="handleSearch">
          <option value="">全部状态</option>
          <option :value="USER_STATUS.NORMAL">正常</option>
          <option :value="USER_STATUS.DISABLED">停用</option>
        </select>
        <button class="btn-search" @click="handleSearch">搜索</button>
      </div>
    </div>

    <div class="users-table">
      <div class="table-header">
        <div class="header-cell">头像</div>
        <div class="header-cell">用户信息</div>
        <div class="header-cell">角色</div>
        <div class="header-cell">状态</div>
        <div class="header-cell">注册时间</div>
        <div class="header-cell">操作</div>
      </div>
      
      <div class="table-body">
        <div class="table-row" v-for="user in userList" :key="user.id">
          <div class="table-cell">
            <div class="user-avatar">
              <img :src="user.avatar || 'https://via.placeholder.com/40x40'" alt="头像">
            </div>
          </div>
          <div class="table-cell">
            <div class="user-info">
              <div class="user-name">{{ user.nickname || '未设置昵称' }}</div>
              <div class="user-phone">{{ formatPhone(user.phone) }}</div>
              <div class="user-realname" v-if="user.realName">
                <span class="real-name-badge" :class="{'verified': user.realNameStatus === REAL_NAME_STATUS.VERIFIED}">
                  {{ user.realName }} ({{ REAL_NAME_STATUS_TEXT[user.realNameStatus] }})
                </span>
              </div>
            </div>
          </div>
          <div class="table-cell">
            <span class="role-badge" :class="user.isDistributor ? 'distributor' : 'customer'">
              {{ user.isDistributor ? '分销员' : '普通用户' }}
            </span>
            <span class="store-badge" v-if="user.isDistributor && user.distributorInfo?.storeName">
              {{ user.distributorInfo.storeName }}
            </span>
          </div>
          <div class="table-cell">
            <span class="status-badge" :class="user.status === USER_STATUS.NORMAL ? 'active' : 'inactive'">
              {{ USER_STATUS_TEXT[user.status] }}
            </span>
          </div>
          <div class="table-cell">
            <span class="date-text">{{ formatDate(user.createdAt) }}</span>
          </div>
          <div class="table-cell">
            <div class="action-buttons">
              <button class="action-btn view" @click="viewUserDetail(user)">查看</button>
              <button class="action-btn manage" 
                      v-if="!user.isDistributor" 
                      @click="showSetDistributor(user)">设为分销员</button>
            </div>
          </div>
        </div>
        
        <!-- 空状态 -->
        <div class="empty-state" v-if="userList.length === 0 && !loading">
          <div class="empty-icon">📋</div>
          <div class="empty-text">暂无用户数据</div>
        </div>
        
        <!-- 加载状态 -->
        <div class="loading-state" v-if="loading">
          <div class="loading-spinner"></div>
          <div class="loading-text">加载中...</div>
        </div>
      </div>
    </div>

    <!-- 分页 -->
    <div class="pagination" v-if="pagination.total > 0">
      <button class="page-btn" 
              :disabled="pagination.current === 1" 
              @click="changePage(pagination.current - 1)">&lt;</button>
      
      <button v-for="page in displayedPages" 
              :key="page" 
              class="page-btn" 
              :class="{ active: page === pagination.current }"
              @click="changePage(page)">
        {{ page }}
      </button>
      
      <button class="page-btn" 
              :disabled="pagination.current === pagination.pages" 
              @click="changePage(pagination.current + 1)">&gt;</button>
    </div>

    <!-- 用户详情弹窗 -->
    <div class="modal" v-if="showDetailModal">
      <div class="modal-overlay" @click="showDetailModal = false"></div>
      <div class="modal-container">
        <div class="modal-header">
          <h3>用户详情</h3>
          <button class="close-btn" @click="showDetailModal = false">×</button>
        </div>
        <div class="modal-body" v-if="currentUser">
          <div class="user-detail-header">
            <div class="user-detail-avatar">
              <img :src="currentUser.avatar || 'https://via.placeholder.com/80x80'" alt="头像">
            </div>
            <div class="user-detail-basic">
              <h4>{{ currentUser.nickname || '未设置昵称' }}</h4>
              <div class="user-tags">
                <span class="user-tag" :class="{'distributor-tag': currentUser.isDistributor}">
                  {{ currentUser.isDistributor ? '分销员' : '普通用户' }}
                </span>
                <span class="user-tag" :class="{'verified-tag': currentUser.realNameStatus === REAL_NAME_STATUS.VERIFIED}">
                  {{ REAL_NAME_STATUS_TEXT[currentUser.realNameStatus] }}
                </span>
                <span class="user-tag" :class="{'active-tag': currentUser.status === USER_STATUS.NORMAL}">
                  {{ USER_STATUS_TEXT[currentUser.status] }}
                </span>
              </div>
            </div>
          </div>
          
          <div class="detail-section">
            <div class="detail-row">
              <div class="detail-label">用户ID</div>
              <div class="detail-value">{{ currentUser.id }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">手机号</div>
              <div class="detail-value">{{ currentUser.phone || '未设置' }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">真实姓名</div>
              <div class="detail-value">{{ currentUser.realName || '未设置' }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">性别</div>
              <div class="detail-value">{{ currentUser.gender ? GENDER_TEXT[currentUser.gender] : '未设置' }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">生日</div>
              <div class="detail-value">{{ currentUser.birthday || '未设置' }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">最后登录</div>
              <div class="detail-value">{{ formatDateTime(currentUser.lastLoginAt) }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">注册时间</div>
              <div class="detail-value">{{ formatDateTime(currentUser.createdAt) }}</div>
            </div>
          </div>
          
          <!-- 分销员信息 -->
          <div class="detail-section" v-if="currentUser.isDistributor && currentUser.distributorInfo">
            <h4 class="section-title">分销员信息</h4>
            <div class="detail-row">
              <div class="detail-label">分销员ID</div>
              <div class="detail-value">{{ currentUser.distributorInfo.distributorId }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">分销码</div>
              <div class="detail-value">{{ currentUser.distributorInfo.distributorCode }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">分销等级</div>
              <div class="detail-value">{{ DISTRIBUTOR_LEVEL_TEXT[currentUser.distributorInfo.level] }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">所属门店</div>
              <div class="detail-value">{{ currentUser.distributorInfo.storeName }}</div>
            </div>
            <div class="detail-row" v-if="currentUser.distributorInfo.parentName">
              <div class="detail-label">上级分销员</div>
              <div class="detail-value">{{ currentUser.distributorInfo.parentName }}</div>
            </div>
            <div class="detail-row">
              <div class="detail-label">分销员状态</div>
              <div class="detail-value">
                <span class="status-badge" :class="currentUser.distributorInfo.status === 1 ? 'active' : 'inactive'">
                  {{ currentUser.distributorInfo.status === 1 ? '激活' : '停用' }}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 设置分销员弹窗 -->
    <div class="modal" v-if="showDistributorModal">
      <div class="modal-overlay" @click="showDistributorModal = false"></div>
      <div class="modal-container">
        <div class="modal-header">
          <h3>设置为分销员</h3>
          <button class="close-btn" @click="showDistributorModal = false">×</button>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label class="form-label">用户</label>
            <div class="form-value">{{ distributorForm.userName }}</div>
          </div>
          
          <div class="form-group">
            <label class="form-label required">所属门店</label>
            <select class="form-select" v-model="distributorForm.storeId" required @change="handleStoreChange">
              <option value="" disabled>请选择门店</option>
              <option v-for="store in storeList" :key="store.id" :value="store.id">
                {{ store.name }}
              </option>
            </select>
            <div class="form-error" v-if="formErrors.storeId">{{ formErrors.storeId }}</div>
          </div>
          
          <div class="form-group">
            <label class="form-label required">分销等级</label>
            <select class="form-select" v-model="distributorForm.level" required @change="handleLevelChange">
              <option value="" disabled>请选择等级</option>
              <option :value="DISTRIBUTOR_LEVEL.LEVEL1">一级分销员</option>
              <option :value="DISTRIBUTOR_LEVEL.LEVEL2">二级分销员</option>
              <option :value="DISTRIBUTOR_LEVEL.LEVEL3">三级分销员</option>
            </select>
            <div class="form-error" v-if="formErrors.level">{{ formErrors.level }}</div>
          </div>
          
          <div class="form-group" v-if="distributorForm.level > DISTRIBUTOR_LEVEL.LEVEL1 && distributorForm.storeId">
            <label class="form-label required">上级分销员</label>
            <select class="form-select" v-model="distributorForm.parentDistributorId" required>
              <option value="" disabled>请选择上级分销员</option>
              <option v-for="distributor in availableParentDistributors" 
                      :key="distributor.distributorId" 
                      :value="distributor.distributorId">
                {{ distributor.nickname }} ({{ DISTRIBUTOR_LEVEL_TEXT[distributor.level] }})
              </option>
            </select>
            <div class="form-hint">上级分销员必须为所选门店的{{ DISTRIBUTOR_LEVEL_TEXT[distributorForm.level - 1] }}</div>
            <div class="form-error" v-if="formErrors.parentDistributorId">{{ formErrors.parentDistributorId }}</div>
          </div>
          
          <div class="form-actions">
            <button class="btn btn-cancel" @click="showDistributorModal = false">取消</button>
            <button class="btn btn-primary" @click="submitSetDistributor" :disabled="submitting">
              {{ submitting ? '提交中...' : '确认设置' }}
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { getUserList, getUserDetail, setDistributor } from '@/api/user'
import { getActiveStores } from '@/api/store'
import { getStoreDistributors } from '@/api/distributor'
import { 
  USER_STATUS, 
  USER_STATUS_TEXT, 
  REAL_NAME_STATUS, 
  REAL_NAME_STATUS_TEXT, 
  USER_TYPE,
  GENDER,
  GENDER_TEXT,
  DISTRIBUTOR_LEVEL,
  DISTRIBUTOR_LEVEL_TEXT
} from '@/utils/userConstants'

// 查询参数
const queryParams = reactive({
  keyword: '',
  userType: USER_TYPE.CUSTOMER,
  realNameStatus: '',
  status: '',
  page: 1,
  size: 10
})

// 列表数据
const userList = ref([])
const loading = ref(false)
const pagination = reactive({
  total: 0,
  current: 1,
  size: 10,
  pages: 0
})

// 详情弹窗
const showDetailModal = ref(false)
const currentUser = ref(null)

// 设置分销员弹窗
const showDistributorModal = ref(false)
const distributorForm = reactive({
  userId: null,
  userName: '',
  storeId: '',
  level: DISTRIBUTOR_LEVEL.LEVEL1,
  parentDistributorId: null
})
const formErrors = reactive({
  storeId: '',
  level: '',
  parentDistributorId: ''
})
const storeList = ref([])
const storeDistributors = ref([]) // 门店分销员列表
const submitting = ref(false)

// 可选的上级分销员列表（计算属性）
const availableParentDistributors = computed(() => {
  // 只能选择大一级的分销员作为上级
  // 例如：设置三级分销员时，只能选择二级分销员作为上级
  return storeDistributors.value.filter(item => item.level === distributorForm.level - 1);
})

// 计算属性：显示的页码
const displayedPages = computed(() => {
  const current = pagination.current
  const pages = pagination.pages
  const result = []
  
  if (pages <= 5) {
    for (let i = 1; i <= pages; i++) {
      result.push(i)
    }
  } else {
    if (current <= 3) {
      for (let i = 1; i <= 5; i++) {
        result.push(i)
      }
    } else if (current >= pages - 2) {
      for (let i = pages - 4; i <= pages; i++) {
        result.push(i)
      }
    } else {
      for (let i = current - 2; i <= current + 2; i++) {
        result.push(i)
      }
    }
  }
  
  return result
})

// 初始化
onMounted(() => {
  fetchUserList()
  fetchStoreList()
})

// 获取用户列表
const fetchUserList = async () => {
  loading.value = true
  try {
    const res = await getUserList(queryParams)
    if (res.code === 200) {
      userList.value = res.data.list
      pagination.total = res.data.total
      pagination.current = res.data.pageNum
      pagination.size = res.data.pageSize
      pagination.pages = res.data.pages
    } else {
      console.error('获取用户列表失败：', res.message)
    }
  } catch (error) {
    console.error('获取用户列表异常：', error)
  } finally {
    loading.value = false
  }
}

// 获取门店列表
const fetchStoreList = async () => {
  try {
    const res = await getActiveStores()
    if (res.code === 200) {
      storeList.value = res.data
    } else {
      console.error('获取门店列表失败：', res.message)
    }
  } catch (error) {
    console.error('获取门店列表异常：', error)
  }
}

// 搜索
const handleSearch = () => {
  queryParams.page = 1
  fetchUserList()
}

// 切换页码
const changePage = (page) => {
  queryParams.page = page
  fetchUserList()
}

// 查看用户详情
const viewUserDetail = async (user) => {
  try {
    const res = await getUserDetail(user.id)
    if (res.code === 200) {
      currentUser.value = res.data
      showDetailModal.value = true
    } else {
      console.error('获取用户详情失败：', res.message)
    }
  } catch (error) {
    console.error('获取用户详情异常：', error)
  }
}

// 显示设置分销员弹窗
const showSetDistributor = (user) => {
  // 重置表单
  Object.keys(formErrors).forEach(key => formErrors[key] = '')
  
  distributorForm.userId = user.id
  distributorForm.userName = user.nickname || user.phone || `用户${user.id}`
  distributorForm.storeId = ''
  distributorForm.level = DISTRIBUTOR_LEVEL.LEVEL1
  distributorForm.parentDistributorId = null
  
  // 清空门店分销员列表
  storeDistributors.value = []
  
  showDistributorModal.value = true
}

// 门店选择变更
const handleStoreChange = async () => {
  // 清空上级分销员
  distributorForm.parentDistributorId = null
  
  // 如果选择了门店，则获取门店分销员列表
  if (distributorForm.storeId) {
    try {
      const res = await getStoreDistributors(distributorForm.storeId)
      if (res.code === 200) {
        storeDistributors.value = res.data
      } else {
        console.error('获取门店分销员失败:', res.message)
      }
    } catch (error) {
      console.error('获取门店分销员异常:', error)
    }
  } else {
    storeDistributors.value = []
  }
}

// 分销等级变更
const handleLevelChange = () => {
  // 清空上级分销员
  distributorForm.parentDistributorId = null
}

// 提交设置分销员
const submitSetDistributor = async () => {
  // 表单验证
  let isValid = true
  
  if (!distributorForm.storeId) {
    formErrors.storeId = '请选择门店'
    isValid = false
  }
  
  if (!distributorForm.level) {
    formErrors.level = '请选择分销等级'
    isValid = false
  }
  
  if (distributorForm.level > DISTRIBUTOR_LEVEL.LEVEL1 && !distributorForm.parentDistributorId) {
    formErrors.parentDistributorId = '二级或三级分销员必须指定上级分销员'
    isValid = false
  }
  
  if (!isValid) return
  
  submitting.value = true
  try {
    const postData = {
      storeId: distributorForm.storeId,
      level: distributorForm.level,
      parentDistributorId: distributorForm.level > DISTRIBUTOR_LEVEL.LEVEL1 ? distributorForm.parentDistributorId : null
    }
    
    const res = await setDistributor(distributorForm.userId, postData)
    if (res.code === 200) {
      alert('设置分销员成功')
      showDistributorModal.value = false
      fetchUserList() // 刷新列表
    } else {
      alert(`设置失败：${res.message}`)
    }
  } catch (error) {
    console.error('设置分销员异常：', error)
    alert(`设置失败：${error.message}`)
  } finally {
    submitting.value = false
  }
}

// 格式化手机号
const formatPhone = (phone) => {
  if (!phone) return '未设置手机号'
  return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}

// 格式化日期
const formatDate = (dateStr) => {
  if (!dateStr) return '-'
  const date = new Date(dateStr)
  return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
}

// 格式化日期时间
const formatDateTime = (dateStr) => {
  if (!dateStr) return '-'
  const date = new Date(dateStr)
  return `${formatDate(dateStr)} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
}
</script>

<style scoped>
.users-page {
  max-width: 1400px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.page-title {
  font-size: 1.8rem;
  font-weight: 600;
  margin: 0;
  color: #2d3748;
}

.header-actions {
  display: flex;
  gap: 15px;
  align-items: center;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  fill: #9ca3af;
}

.search-input {
  padding: 10px 15px 10px 40px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  width: 250px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: #5856d6;
}

.filter-select {
  padding: 10px 15px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
}

.filter-select:focus {
  border-color: #5856d6;
}

.btn-search {
  padding: 10px 20px;
  background: #5856d6;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-search:hover {
  background: #4645b2;
}

.users-table {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
  margin-bottom: 25px;
}

.table-header {
  display: grid;
  grid-template-columns: 80px 1fr 120px 100px 120px 180px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.header-cell {
  padding: 15px 20px;
  font-weight: 600;
  color: #4a5568;
  font-size: 0.9rem;
}

.table-body {
  background: white;
  position: relative;
  min-height: 200px;
}

.table-row {
  display: grid;
  grid-template-columns: 80px 1fr 120px 100px 120px 180px;
  border-bottom: 1px solid #f1f5f9;
  transition: background-color 0.2s;
}

.table-row:hover {
  background: #f8fafc;
}

.table-cell {
  padding: 15px 20px;
  display: flex;
  align-items: center;
  font-size: 0.9rem;
}

.user-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-name {
  font-weight: 500;
  color: #2d3748;
}

.user-phone {
  color: #718096;
  font-size: 0.8rem;
}

.user-realname {
  margin-top: 4px;
}

.real-name-badge {
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(236, 72, 153, 0.1);
  color: #ec4899;
}

.real-name-badge.verified {
  background: rgba(22, 163, 74, 0.1);
  color: #16a34a;
}

.role-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
}

.role-badge.customer {
  background: rgba(88, 86, 214, 0.1);
  color: #5856d6;
}

.role-badge.distributor {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.store-badge {
  margin-top: 4px;
  font-size: 0.8rem;
  color: #6b7280;
  display: block;
}

.status-badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
}

.status-badge.active {
  background: rgba(34, 139, 34, 0.1);
  color: #16a34a;
}

.status-badge.inactive {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.date-text {
  color: #718096;
  font-size: 0.9rem;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn.view {
  background: rgba(88, 86, 214, 0.1);
  color: #5856d6;
}

.action-btn.view:hover {
  background: rgba(88, 86, 214, 0.2);
}

.action-btn.manage {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.action-btn.manage:hover {
  background: rgba(245, 158, 11, 0.2);
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 30px;
}

.page-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: white;
  color: #4a5568;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.page-btn:hover {
  border-color: #5856d6;
  color: #5856d6;
}

.page-btn.active {
  background: #5856d6;
  color: white;
  border-color: #5856d6;
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.empty-state, .loading-state {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
}

.empty-icon, .loading-spinner {
  font-size: 2rem;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e2e8f0;
  border-top-color: #5856d6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-text, .loading-text {
  color: #718096;
  font-size: 1rem;
}

/* 弹窗样式 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.modal-container {
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  z-index: 101;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 20px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: #2d3748;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #718096;
  cursor: pointer;
  line-height: 1;
  padding: 0 5px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(90vh - 80px);
}

/* 用户详情样式 */
.user-detail-header {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e2e8f0;
}

.user-detail-avatar img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
}

.user-detail-basic {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.user-detail-basic h4 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: #2d3748;
}

.user-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.user-tag {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
  background: #f3f4f6;
  color: #6b7280;
}

.user-tag.distributor-tag {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.user-tag.verified-tag {
  background: rgba(22, 163, 74, 0.1);
  color: #16a34a;
}

.user-tag.active-tag {
  background: rgba(34, 139, 34, 0.1);
  color: #16a34a;
}

.detail-section {
  margin-bottom: 20px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 15px 0;
  color: #2d3748;
  padding-bottom: 10px;
  border-bottom: 1px solid #e2e8f0;
}

.detail-row {
  display: flex;
  margin-bottom: 12px;
}

.detail-label {
  width: 120px;
  font-weight: 500;
  color: #4a5568;
}

.detail-value {
  flex: 1;
  color: #2d3748;
}

/* 表单样式 */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #4a5568;
}

.form-label.required::after {
  content: "*";
  color: #ef4444;
  margin-left: 4px;
}

.form-select, .form-input {
  width: 100%;
  padding: 10px 15px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-select:focus, .form-input:focus {
  border-color: #5856d6;
}

.form-error {
  margin-top: 4px;
  color: #ef4444;
  font-size: 0.8rem;
}

.form-hint {
  margin-top: 4px;
  color: #718096;
  font-size: 0.8rem;
}

.form-value {
  padding: 10px 0;
  font-weight: 500;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 15px;
  margin-top: 30px;
}

.btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel {
  background: white;
  border: 1px solid #e2e8f0;
  color: #4a5568;
}

.btn-cancel:hover {
  border-color: #cbd5e1;
  color: #2d3748;
}

.btn-primary {
  background: #5856d6;
  border: 1px solid #5856d6;
  color: white;
}

.btn-primary:hover {
  background: #4645b2;
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.select-avatar-hint {
  font-size: 0.7rem;
  color: #5856d6;
  margin-left: 5px;
}
</style> 